package com.qf.edu.dao.impl;

import com.qf.edu.dao.Login;
import com.qf.edu.entity.Users;
import com.qf.edu.utils.DBUtils;
import org.apache.commons.dbutils.QueryRunner;
import org.apache.commons.dbutils.handlers.BeanHandler;

import java.sql.SQLException;

/**
 * @author:huayuzhuo
 * @email:2798866329@qq.com
 * @desc:登录接口类
 * @datatime: 2022/5/24 10:34
 */
public class LoginImpl implements Login {
    @Override
    public Users login(Users users) {
        //加载获取资源包连接数据库
        QueryRunner queryRunner = new QueryRunner(DBUtils.getDataSource());
        String sql = "SELECT * FROM users WHERE `name` = ? AND `password` = ? AND `jobName` = ?";

        try {
            Users query = queryRunner.query(sql, new BeanHandler<>(Users.class),new Object[]{users.getName(),users.getPassword(),users.getJobName()});
            return query;
        } catch (SQLException e) {
            e.printStackTrace();
        }
        return null;
    }

}
